package gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import connection.Reader;

/**
 * Trida reprezentujici okno vyzvy
 * 
 * @author dove
 * 
 */
public class ChalengeInfoWin extends InternalFrame implements ActionListener {

	private static final long serialVersionUID = 1L;

	private JLabel lText;

	private JButton accept;

	private JButton decline;

	/**
	 * Nastavuje parametry okna
	 * 
	 * @param text
	 *            nazev okna
	 */
	public ChalengeInfoWin(String name) {
		super(name);
		this.setPosition(200, 200);

		JPanel pan = new JPanel();
		pan.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		c.insets = new Insets(10, 10, 10, 10);
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = 2;
		lText = new JLabel(name);
		pan.add(lText, c);

		c.anchor = GridBagConstraints.LINE_END;
		c.gridwidth = 1;
		c.gridy = 1;
		accept = new JButton(messages.getString("Accept"));
		pan.add(accept, c);
		accept.addActionListener(this);

		c.gridx = 1;
		decline = new JButton(messages.getString("Decline"));
		pan.add(decline, c);
		decline.addActionListener(this);

		this.add(pan);
		this.pack();
		this.setMinimumSize(new Dimension(100, 100));
	}

	/**
	 * Nastavuje text ktery ma byt v okne zobrazen
	 * 
	 * @param text
	 *            informacni text
	 */
	public void setText(String text) {
		lText.setText(text);
		this.pack();
		this.updateUI();
	}

	public void actionPerformed(ActionEvent e) {
		Object action = e.getSource();
		if (action.equals(accept)) {
			Reader.sendString("accept");
		}
		if (action.equals(decline)) {
			Reader.sendString("decline");
		}
		this.setVisible(false);
	}
}
